package com.youyiwen.Mapper;

import com.youyiwen.Bean.ChatList;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: zhaoyang
 * @Date: 2021/04/18
 */
@Mapper
public interface ChatListMapper {

    @Insert("insert into chat_list values(#{id},#{me},#{others},#{lastReplyTime},#{msgCount})")
    public void insertChatList(ChatList chatList);

    @Select("select * from chat_list where me = #{me} order by last_reply_time desc")
    public List<ChatList> chatList(String me);

    @Select("select id from chat_list where me =#{me} and others = #{others}")
    public String selectChatId(String me,String others);

    @Update("update chat_list set last_reply_time = #{current} " +
            "where (me = #{me} and others = #{others}) or (me = #{others} and others = #{me})")
    public void updateLastReplyTime(@Param("me") String me,
                                    @Param("others") String others,
                                    @Param("current") Long current);

    @Update("update chat_list set msg_count = msg_count + 1 where me = #{receiver} and others = #{sender}")
    public void incMsgCount(String receiver,String sender);

    @Update("update chat_list set msg_count = 0 where me = #{receiver} and others = #{sender}")
    public void updateMsgCount(String receiver,String sender);


}
